package com.example.eldersystem.operatedata.mapper;

import com.example.eldersystem.operatedata.model.OldPerson;
import org.apache.ibatis.annotations.*;
import java.util.List;


public interface OldPersonMapper {

    @Insert("insert into oldperson_info(username,gender,phone,id_card,birthday,checkin_date,checkout_date," +
            "imgset_dir,profile_photo,health_state,description,room_number," +
            "firstguardian_name,firstguardian_relationship,firstguardian_phone,firstguardian_wechat," +
            "secondguardian_name,secondguardian_relationship,secondguardian_phone,secondguardian_wechat) " +
            "values (#{userName},#{gender},#{phone},#{idCard},#{birthday},#{checkInDate},#{checkOutDate}," +
            "#{imgsetDir},#{profilePhoto},#{healthState},#{description},#{roomNumber}," +
            "#{firstGuardianName},#{firstGuardianRelationship},#{firstGuardianPhone},#{firstGuardianWechat}," +
            "#{secGuardianName},#{secGuardianRelationship},#{secGuardianPhone},#{secGuardianWechat}) ")
    int addOldPerson(OldPerson oldPerson);

    @Update("update oldperson_info " +
            "set username=#{userName}," +
            "gender=#{gender}," +
            "phone=#{phone}," +
            "id_card=#{idCard}," +
            "birthday=#{birthday}," +
            "checkin_date=#{checkInDate}," +
            "checkout_date=#{checkOutDate},"+
            "imgset_dir=#{imgsetDir}," +
            "profile_photo=#{profilePhoto}," +
            "health_state=#{healthState}," +
            "description=#{description}," +
            "room_number=#{roomNumber}," +
            "firstguardian_name=#{firstGuardianName}," +
            "firstguardian_relationship=#{firstGuardianRelationship}," +
            "firstguardian_phone=#{firstGuardianPhone}," +
            "firstguardian_wechat=#{firstGuardianWechat}," +
            "secondguardian_name=#{secGuardianName}," +
            "secondguardian_relationship=#{secGuardianRelationship}," +
            "secondguardian_phone=#{secGuardianPhone}," +
            "secondguardian_wechat=#{secGuardianWechat}" +
            "where id = #{id}")
    int updateOldPerson(OldPerson oldPerson);

    @Update("update oldperson_info set profile_photo=#{profilePhoto} where id=#{id}")
    int updateProfile(int id,String profilePhoto);

    @Delete("delete from oldperson_info where id = #{id}")
    int deleteOldPerson(int id);

    @Select("select count(*) from oldperson_info")
    int selectOldPersonNum();

    @Select("select * from oldperson_info limit #{from},#{num}")
    @Results(id="select1",value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "userName",column = "username"),
            @Result(property = "gender",column = "gender"),
            @Result(property = "phone",column = "phone"),
            @Result(property = "idCard",column = "id_card"),
            @Result(property = "birthday",column = "birthday"),
            @Result(property = "checkInDate",column = "checkin_date"),
            @Result(property = "checkOutDate",column = "checkout_date"),
            @Result(property = "imgsetDir",column = "imgset_dir"),
            @Result(property = "profilePhoto",column = "profile_photo"),
            @Result(property = "roomNumber",column = "room_number"),
            @Result(property = "healthState",column = "health_state"),
            @Result(property = "firstGuardianName",column = "firstguardian_name"),
            @Result(property = "firstGuardianRelationship",column = "firstguardian_relationship"),
            @Result(property = "firstGuardianPhone",column = "firstguardian_phone"),
            @Result(property = "firstGuardianWechat",column = "firstguardian_wechat"),
            @Result(property = "secGuardianName",column = "secondguardian_name"),
            @Result(property = "secGuardianRelationship",column = "secondguardian_relationship"),
            @Result(property = "secGuardianPhone",column = "secondguardian_phone"),
            @Result(property = "secGuardianWechat",column = "secondguardian_wechat"),
            @Result(property = "description",column = "description"),
    })
    List<OldPerson> selectOldPerson(int from, int num);

    @Select("select count(*) from oldperson_info where username like concat('%',#{userName},'%')")
    int selectOldPersonNum2(String userName);

    @Select("select * from oldperson_info where username like concat('%',#{userName},'%')")
    @Results(id="select2",value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "userName",column = "username"),
            @Result(property = "gender",column = "gender"),
            @Result(property = "phone",column = "phone"),
            @Result(property = "idCard",column = "id_card"),
            @Result(property = "birthday",column = "birthday"),
            @Result(property = "checkInDate",column = "checkin_date"),
            @Result(property = "checkOutDate",column = "checkout_date"),
            @Result(property = "imgsetDir",column = "imgset_dir"),
            @Result(property = "profilePhoto",column = "profile_photo"),
            @Result(property = "roomNumber",column = "room_number"),
            @Result(property = "healthState",column = "health_state"),
            @Result(property = "firstGuardianName",column = "firstguardian_name"),
            @Result(property = "firstGuardianRelationship",column = "firstguardian_relationship"),
            @Result(property = "firstGuardianPhone",column = "firstguardian_phone"),
            @Result(property = "firstGuardianWechat",column = "firstguardian_wechat"),
            @Result(property = "secGuardianName",column = "secondguardian_name"),
            @Result(property = "secGuardianRelationship",column = "secondguardian_relationship"),
            @Result(property = "secGuardianPhone",column = "secondguardian_phone"),
            @Result(property = "secGuardianWechat",column = "secondguardian_wechat"),
            @Result(property = "description",column = "description"),
    })
    List<OldPerson> selectOldPersonByName(String userName);
}
